//
//  ImageScrollView.m
//  TAUi
//
//  Created by Lin Buken on 16/1/11.
//  Copyright © 2016年 com.aiton. All rights reserved.
//

#import "ImageScrollView.h"

@implementation ImageScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.minimumZoomScale = 1.0;
        self.maximumZoomScale = 2.5;
        self.delegate =self;
        
        self.theImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:self.theImageView];
        
        
//        添加双击事件
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomInandOut:)];
        doubleTap.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTap];
        
    }
    return self;
}

#pragma mark UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
    return self.theImageView;
}

- (void)zoomInandOut:(UITapGestureRecognizer *)tap
{
    if (self.zoomScale>1.0) {
        [self setZoomScale:1.0 animated:YES];
    }else
    {
        CGPoint point = [tap locationInView:self];
        [self zoomToRect:CGRectMake(point.x-40, point.y-40, 80, 80) animated:YES];
    }
}


@end
